#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

/* This program creates three files and tries to write 48 differently.
 * You might want to see what is written to the files using "cat" and "xxd".
 *  b_char - a single char is written to that file. The char's number is 48
 *  	decimal (30 hex, and '0' ascii). Its size is 1 byte long.
 *  b_text - a string "48" is written to the file. The file size is 2 bytes
 *  	(one for char '4' and the other for char '8').
 *  b_int - a single int (of value 48) is written to that file. If you use
 *  	a 32bit machine the size of the file will be 4 byte.
 *	Therefore, "cat" and "xxd" will "show" 4 chars.
 * You may also want to change the size of the written values, in order to see
 * how it effects the written data.
 */
int main2(void)
{
	int fd, fd2, fd3;
	int size1, size2, size3;
	char ch;
	char *str;
	int num;

	// Create b_char and write a char into it
	fd = open("b_char", O_CREAT | O_WRONLY, 0666);
	size1 = sizeof(char); // We write a single char
	ch = 48;
	write(fd, &ch, size1);
	close(fd);

	// Create b_text and write a string into it
	fd2 = open("b_text", O_CREAT | O_WRONLY, 0666);
	size2 = 2 * sizeof(char); // We write 2 chars
	str = "48";
	write(fd2, str, size2);
	close(fd2);

	// Create b_int and write an integer into it
	fd3 = open("b_int", O_CREAT | O_WRONLY, 0666);
	size3 = sizeof(int); // We write a single integer
	num = 48;
	write(fd3, &num, size3);
	close(fd3);

	return 0;
}
